package ui;

import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import draft.FantasyManager;
import draft.League;
import draft.Team;


public class OrderPanel extends JPanel{
	
	JLabel[] teams_text;
	
	public OrderPanel(){
		setBackground(new Color(240,240,240));
		teams_text = new JLabel[League.size];
		Team[] teams = FantasyManager.league.teams;
		int rows = (int) Math.ceil(League.size/8.0);
		int cols = (int) Math.ceil(League.size/rows);
		setLayout(new GridLayout(rows, cols));
		for (int i = 0; i < teams_text.length; i++){
			teams_text[i] =new JLabel (teams[i].name + "");
			teams_text[i].setHorizontalTextPosition(SwingConstants.CENTER);
			if (i == FantasyManager.userTeam()){
				teams_text[i].setFont(new Font("sans serif", Font.BOLD, 12));
			}
			if (i == FantasyManager.currentTeam()){
				teams_text[i].setFont(new Font("sans serif", Font.ITALIC, 12));
			}
			if (i == FantasyManager.currentTeam() && i == FantasyManager.userTeam()){
				teams_text[i].setFont(new Font("sans serif", Font.ITALIC + Font.BOLD, 12));
			}
			if (i != FantasyManager.userTeam() && i != FantasyManager.currentTeam()){
				teams_text[i].setFont(new Font("sans serif", Font.PLAIN, 12));
			}
			teams_text[i].setHorizontalAlignment(SwingConstants.CENTER);
			add(teams_text[i]);
		}
		setVisible(true);
	}
	
	public void updateText(){
		for (int i = 0; i < teams_text.length; i++){
			if (i == FantasyManager.userTeam()){
				teams_text[i].setFont(new Font("sans serif", Font.BOLD, 12));
			}
			if (i == FantasyManager.currentTeam()){
				teams_text[i].setFont(new Font("sans serif", Font.ITALIC, 12));
			}
			if (i == FantasyManager.currentTeam() && i == FantasyManager.userTeam()){
				teams_text[i].setFont(new Font("sans serif", Font.ITALIC + Font.BOLD, 12));
			}
			if (i != FantasyManager.userTeam() && i != FantasyManager.currentTeam()){
				teams_text[i].setFont(new Font("sans serif", Font.PLAIN, 12));
			}
			teams_text[i].setHorizontalAlignment(SwingConstants.CENTER);
		}
	}

}
